#Lindsay Ergenekan 
#ergenekl@onid.oregonstate.edu
#CS311-400
#Homework2 - Question 2

import getopt, sys, os

def main(argv):
   try: 
      opt, args = getopt.getopt(argv, "t:c", ["term", "class"])
   except getopt.GetoptError, err:
      print str(err)
      sys.exit(2)
   output = None
   verbose = False
   for o, a in opt: 
      if o in ("-t", "--term"):
         term = sys.argv[2]
         print term
      elif o in ("-c", "--class"): 
         classname = sys.argv[4]
         print classname
      else: 
         assert False, "unhandled option"
         print "Please check your arguments"
   create_dir(term, classname)
   create_links(term, classname)

def create_dir(term, classname):
   direct = term + "_" + classname
   print direct
       
   if os.path.isdir(direct):
      print "This directory already exists."
   else:
      os.mkdir("./" + direct + "/")
      os.mkdir(direct + "/assignments/")   
      os.mkdir(direct + "/examples/")
      os.mkdir(direct + "/exams/")
      os.mkdir(direct + "/lecture_notes")
      os.mkdir(direct + "/submissions")
      print "Directories made"

def create_links(term, classname):
   readme_link = "/usr/local/classes/eecs/" + term  + "/" + classname + "/src/README"
   if os.path.exists(readme_link):
     print "There is already a link called read me"
   else: 
      os.symlink(readme_link, 'README')
   

   src_class_link = "/usr/local/classes/eecs/" + term  + "/" + classname + "/src"
   if os.path.isfile('src_class'):
      print "There is already a link called src_class"
   else:    
      os.symlink(src_class_link, 'src_class')  


if __name__ == "__main__":
   main(sys.argv[1:])
